package org.csu.code.api.controller;

import org.csu.code.api.common.CommonResponse;
import org.csu.code.api.entity.Category;
import org.csu.code.api.entity.Item;
import org.csu.code.api.entity.Product;
import org.csu.code.api.service.CatalogService;
import org.csu.code.api.service.OrderService;
import org.csu.code.api.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/catalog/search")
public class SearchController {

    @Autowired
    CatalogService catalogService;
    @Autowired
    OrderService orderService;

    @GetMapping("/products/{keyword}")
    @ResponseBody
    public CommonResponse<List<Product>> searchProduct(@PathVariable("keyword") String keyword){
        return catalogService.searchProduct(keyword);
    }

    @GetMapping("/items/{keyword}")
    @ResponseBody
    public CommonResponse<List<Item>> searchItem(@PathVariable("keyword") String keyword){
        return catalogService.searchItem(keyword);
    }

    @GetMapping("/categories/{keyword}")
    @ResponseBody
    public CommonResponse<List<Category>> searchCategory(@PathVariable("keyword") String keyword){
        return catalogService.searchCategory(keyword);
    }
    
    @GetMapping("/orders/{keyword}")
    @ResponseBody
    public CommonResponse<List<OrderVO>> searchOrder(@PathVariable("keyword") String keyword){
        return orderService.searchOrderList(keyword);
    }
}
